# Maintainer: Felix Yan <felixonmars@archlinux.org>
# Maintainer: Chih-Hsuan Yen <yan12125@archlinux.org>

pkgname=nvchecker
pkgver=2.12
# curl https://api.github.com/repos/lilydjwg/nvchecker/git/ref/tags/v$pkgver | jq -r .object.sha
_tag=7df19d25b745481622f23668036020b664e6ee66
pkgrel=2
pkgdesc="New version checker for software releases"
arch=('any')
url="https://github.com/lilydjwg/nvchecker"
license=('MIT')
depends=('python' 'python-structlog' 'python-platformdirs' 'python-tornado' 'python-pycurl')
makedepends=('git' 'python-build' 'python-installer' 'python-setuptools' 'python-wheel'
             # for building docs
             'python-docutils' 'python-pygments'
             # optional deps
             'python-gobject' 'python-toml' 'python-aiohttp' 'python-httpx')
checkdepends=('python-pytest' 'python-pytest-asyncio' 'python-pytest-httpbin' 'python-flaky'
              'pyalpm' 'python-awesomeversion' 'python-lxml' 'git')
optdepends=(
  'pyalpm: for using "sort_version_key = vercmp" in configuration files and the alpm source'
  'python-awesomeversion: for using "sort_version_key = awesomeversion" in configuration files'
  'python-lxml: for the htmlparser source'
  'python-packaging: for the pypi source'
  'python-toml: for nvchecker-ini2toml script'
  'python-aiohttp: alternative HTTP backend'
  'python-httpx: alternative HTTP backend'
  'git: support for git repositories'
  'python-gobject: for nvchecker-notify'
  'libnotify: for nvchecker-notify'
)
source=("git+https://github.com/lilydjwg/nvchecker.git?signed#tag=$_tag"
        # see https://github.com/lilydjwg/nvchecker/pull/233
        "${pkgname}_fix_symlinks.patch::https://github.com/lilydjwg/nvchecker/pull/233/commits/1986f2953a0e1dda8abb42b9d8847308546f4ea6.patch"
)
sha512sums=('SKIP'
            'd55d46774773aa8cd2d35ef3f1531d747affa03a9d9f176967e82348b609b22ed755b71b206b384464840015b29a2c1725e57e75fdfe9e73c9b66d4a19fb67ad')
validpgpkeys=(
  # No direct trust chain. Some related stuffs:
  # https://api.github.com/users/lilydjwg/gpg_keys
  # https://zh.wikipedia.org/wiki/User:Lilydjwg
  '356690A1E7404E30D0E902B2E64D049594A54F54'
)

_backports=(
  # Fix test_alpmfiles in Arch chroots
  'd9888cc49d3531a947e7b443a3bab47a7e09da14'
  # bump android-sdk-cmake and xml2 version
  'fe1342e9fb39774e63d2f650db8e04f50d3355a9'
)

pkgver() {
  cd nvchecker
  git describe --tags | sed 's/^v//;s/-/+/g'
}

prepare() {
  cd nvchecker

  patch --verbose --strip=1 --input="../${pkgname}_fix_symlinks.patch"

  # this loop is stolen from core/systemd :)
  local _c
  for _c in "${_backports[@]}"; do
    git log --oneline -1 "${_c}"
    git cherry-pick -n "${_c}"
  done
}

build() {
  cd nvchecker
  python -m build --wheel --no-isolation

  make -C docs man
}

check() {
  cd nvchecker
  pytest
}

package() {
  cd nvchecker
  python -m installer --destdir="$pkgdir" dist/*.whl
  install -Dm644 LICENSE -t "$pkgdir"/usr/share/licenses/$pkgname

  # bash completion scripts & docs
  install -Dm644 scripts/nvtake.bash_completion "$pkgdir"/usr/share/bash-completion/completions/nvtake
  install -Dm644 docs/usage.rst -t "$pkgdir"/usr/share/doc/$pkgname/
  install -Dm644 sample_config.toml -t "$pkgdir"/usr/share/doc/$pkgname/
  install -Dm644 docs/_build/man/nvchecker.1 -t "$pkgdir"/usr/share/man/man1/
}

# vim:set ts=2 sw=2 et:
